﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints.ObjectConstraints
{
  [TestClass]
  public class IsNotNullConstraintTest
    : ConstraintTestBase<ObjectStub>
  {
    public class Validator
      : ValidatorBase<ObjectStub>
    {
      public Validator()
      {
        DefineRulesFor(ctx => ctx.MyStringProperty1).IsNotNull();
        DefineRulesFor(ctx => ctx.MyObjectProperty1).IsNotNull();
      }
    }

    public IsNotNullConstraintTest() : base(new Validator(), 2) { }

    [TestMethod]
    public void TestConstraintVerified()
    {
      ValidateConstraintVerfied(CreateContext("Not Null"));
    }

    [TestMethod]
    public void TestConstraintViolated()
    {
      const String ruleViolation = "A value is required";

      ValidateConstraintViolated(CreateContext(null), ruleViolation);
    }

    public ObjectStub CreateContext(String value)
    {
      var result = new ObjectStub();

      result.MyStringProperty1 = value;
      result.MyObjectProperty1 = value;

      return result;
    }
  }
}
